package ch6;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/LoginServlet")
public class LoginServlet extends HttpServlet {
    private String userName;

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String userCode = request.getParameter("userCode");
String userPassword = request.getParameter("userPassword");
UserDao userDao = new UserDao();
UserBean user = userDao.findByUserCode(userName,userPassword);
if (user == null){
    request.setAttribute("message","欢迎登录"+UserBean.getuserName());
    request.getRequestDispatcher("/success.jsp").forward(request,response);
}else {
    request.setAttribute("message","登录失败，请重新登录");
    request.getRequestDispatcher("/login.jsp").forward(request,response);
}
    }

}
